package com.qf.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.qf.mapper.CarMapper;
import com.qf.model.Car;
import com.qf.service.CarService;
import com.qf.util.ResultData;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;

/**
 * --- 天道酬勤 ---
 *
 * @author shengzhongzheng
 * @desc
 */
@Service
public class CarServiceImpl implements CarService {

    @Autowired
    private CarMapper carMapper;

    @Override
    public ResultData findAll(HashMap<String, Object> map) {
        String pageNo = (String) map.get("page");
        String pageSize = (String) map.get("limit");

        PageHelper.startPage(Integer.parseInt(pageNo),Integer.parseInt(pageSize));

        List<Car> list = carMapper.findAll(map);

        PageInfo<Car> info = new PageInfo<>(list);

        return ResultData.ok(list, (int)info.getTotal());
    }
}
